package com.blog.back.controller;

import java.util.Arrays;
import java.util.Map;

import com.blog.utils.R;
import com.blog.vo.UsersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.blog.entity.UsersEntity;
import com.blog.back.service.UsersService;
import com.blog.utils.PageUtils;



/**
 * 
 *
 * @author codedorado
 * @email codedorado@foxmail.com
 * @date 2020-08-15 15:26:05
 */
@RestController
@RequestMapping("back/users")
public class UsersController {
    @Autowired
    private UsersService usersService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("back:users:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = usersService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{usersId}")
    // @RequiresPermissions("back:users:info")
    public R info(@PathVariable("usersId") Long usersId){
		// UsersEntity users = usersService.getById(usersId);
        UsersVO user = usersService.getUser(usersId);
        return R.ok().put("data", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("back:users:save")
    public R save(@RequestBody UsersEntity users){
		usersService.save(users);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("back:users:update")
    public R update(@RequestBody UsersEntity users){
		usersService.updateById(users);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("back:users:delete")
    public R delete(@RequestBody Long[] usersIds){
		usersService.removeByIds(Arrays.asList(usersIds));

        return R.ok();
    }

}
